﻿
<?php 
    require 'comm/db.php';
    session_start();
    // 是否提交
    if($_POST){
        $code = $_POST['code'];
        $re_code =  $_SESSION['code'];
        if ($code ==$re_code){
            $phone = empty($_POST['name'])?$re=0:$_POST['name'];
            $pwd = empty($_POST['pwd'])?$re=0:$_POST['pwd'];
            $login_cid = empty($_POST['login_cid'])?$re=0:$_POST['login_cid'];
            $login = new DB();
            $re = $login->login($phone, $pwd,$login_cid);
            if($re){
                //1 如果登陆成功,那么把用户名和密码存储在session中
                
                $_SESSION['login_name'] = $re['name'];
                $_SESSION['login_phone'] = $phone;
                $_SESSION['login_pwd'] = $pwd;
                $_SESSION['login_role'] = $login->getRoleNameByRoleId($re['role_id']);
                //如果是老师
                if($login_cid=='teacher_info'){
                	$id =  $re['teac_id'];
                	$_SESSION['login_class']=$login->getTeacherClassNumById($re['teac_id']);
                }else{
                	$id = $re['stu_id'];
                	$_SESSION['login_class']=$login->getClassNameByClassId($re['class_id']);	
                }
                $_SESSION['login_uid'] = $id;
              //  var_dump($_SESSION);exit;
                echo "<script type='text/javascript'>alert('登录成功');window.location.href='a_index.php'</script>";
            }
        }else{
        	//echo '111';exit;
                echo "<script type='text/javascript'>alert('登录失败'); </script>";
            }
    }
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="static/h-ui/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<link href="static/h-ui/css/bootstrapSwitch.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="static/h-ui/js/bootstrapSwitch.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script><![endif]-->
<title>实训中心考勤OA系统 1.0</title>
<meta name="keywords" content="校内请假OA系统">
<meta name="description" content="校内请假OA系统">
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
	<div id="loginform" class="loginBox">
		<form class="form form-horizontal" action="login.php" method="post">
			<div class="row cl">
				<label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
				<div class="formControls col-xs-8">
					<input id="" name="name" type="text" placeholder="账户" class="input-text size-L">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
				<div class="formControls col-xs-8">
					<input id="" name="pwd" type="password" placeholder="密码" class="input-text size-L">
				</div>
			</div>
			<div class="row cl">
				<div class="formControls col-xs-8 col-xs-offset-3">
					<input class="input-text size-L" name = 'code' type="text" placeholder="验证码" onblur="if(this.value==''){this.value='验证码:'}" onclick="if(this.value=='验证码:'){this.value='';}" value="验证码:" style="width:150px;">
					<img src="comm/xs_code.php" alt="看不清楚，换一张"  id ='code' onclick="newgdcode(this,this.src);"/>
				</div>
			</div>
			<div class="row cl">
			<div class="formControls col-xs-8 col-xs-offset-3">
				<div class="bs-docs-example">
				  <div id="mySwitch" class="switch" data-on-label="学生" data-off-label="老师"  data-on="primary" data-off="info">
				    <input type="checkbox" name = 'shenfen' value = '1'  checked />
				  </div>
				</div>
			</div>
				<!-- <div class="formControls col-xs-8 col-xs-offset-3">
					<label for="online"><input type="radio" name="login_cid" id="online" value="student_info">学生</label>
					<label for="online"><input type="radio" name="login_cid" id="online" value="teacher_info">老师</label>
					<label for="online"><input type="checkbox" name="login_cid" id="online" value="">行政</label>
				</div> -->
			</div>
			<div class="row cl">
				<div class="formControls col-xs-8 col-xs-offset-3">
					<input name='login_cid' id = 'login_cid' type="hidden" value = 'student_info' />
					<input name="" type="submit" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
					<input name="" type="reset" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;">
				</div>
			</div>
		</form>
	</div>
</div>
<div class="footer">Copyright 湖南厚溥教育科技有限公司 by H-ui.admin.page.v3.0</div>

<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="static/h-ui/js/code.js"></script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();

function newgdcode(obj,url) { 
	alert(1111);
	obj.src = url+ '?' + Math.random(); 

	//后面传递一个随机参数，否则在IE7和火狐下，不刷新图片  http://localhost/my_pro/index.php
} 

$('#mySwitch').on('switch-change', function (e, data) {

    var $el = $(data.el)
      , value = data.value;
    if(value ==false){
    	 $('#login_cid').val('teacher_info');
    }else{
    	$('#login_cid').val('student_info');
    }
});
</script>
</body>
</html>